package org.zero.controller;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.zero.model.User;

/**
 * @author Zero
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("get")
    public User getUser() {
        return User.builder()
                .id(1)
                .name("小明")
                .password("abc123")
                .date(new Date())
                .build();
    }

    @GetMapping("list")
    public List<User> listUser() {
        List<User> list = new ArrayList<>();

        list.add(User.builder()
                .id(1)
                .name("小杰")
                .password("abc123")
                .date(new Date(4878683746767L))
                .build());
        list.add(User.builder()
                .id(2)
                .name("小可")
                .password("xxxnnn")
                .date(new Date(975271474754L))
                .build());

        return list;
    }

    @PostMapping("/post")
    public void getUser(@RequestBody User user) {
        System.out.println(user);
    }
}
